/** @file    MediaTrack.cpp
 *  @author  Alessandro Polo
 *  @version $Id: MediaTrack.cpp 2829 2010-08-02 20:45:47Z alex $
 *  @brief
 * File containing methods for the wosh::entertainment::MediaTrack class.
 * The header for this class can be found in MediaTrack.h, check that file
 * for class description.
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/
 
 #include <framework/entertainment/MediaTrack.h>

 #include <core/ObjectAllocator.h>
 #include <core/List.h>
 #include <core/Table.h>
 #include <core/Functional.h>
 #include <core/DataModels.h>


using namespace std;
namespace wosh {
 namespace entertainment {

 WOSH_REGISTER(wosh::entertainment::MediaTrack, "wosh::ISerializable", 1.0, _static_MediaTrack )

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTORS

MediaTrack::MediaTrack()
	: index(-1) {
	clear();
 }

MediaTrack::MediaTrack( const ResourcePath& fullpath )
	: index(-1) {
	clear();
	setTrack(fullpath);
 }

//////////////////////////////////////////////////////////////////////////////////////////////// CONSTRUCTORS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

void MediaTrack::clear() {
	this->index = -1;
	this->track.clear();
	Properties.clear();

	Properties.set(_MediaTrack_KEY_Index, -1);
	Properties.set(_MediaTrack_KEY_Path, "");
	Properties.set(_MediaTrack_KEY_Length, Variant_TS(0) );
	Properties.set(_MediaTrack_KEY_SizeKb, 0);

	Properties.set(_MediaTrack_KEY_Artist, "");
	Properties.set(_MediaTrack_KEY_Album, "");
	Properties.set(_MediaTrack_KEY_Title, "");
	Properties.set(_MediaTrack_KEY_Genre, "");

	Properties.set(_MediaTrack_KEY_TrackNumber, -1);
	Properties.set(_MediaTrack_KEY_Description, "");
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

bool MediaTrack::updateHash( DataHashContext* hash_context ) const {
	if ( hash_context == NULL ) return false;
	bool ret = true;
	ret = this->track.updateHash(hash_context) & ret;
	ret = this->Properties.updateHash(hash_context) & ret;
	return ret;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

DataFieldCollector<MediaTrack>* MediaTrack::getDataFields() {
	DataFieldCollector<MediaTrack>* fields = new DataFieldCollector<MediaTrack>();
	fields->add<long, Variant>(&MediaTrack::getIndex, "Index", 0);
	fields->add<const ResourcePath&, ResourcePath>(&MediaTrack::getTrack, "Path", 1);
	fields->add<std::string,Variant>(&MediaTrack::getArtist, "Artist", 2);
	fields->add<std::string,Variant>(&MediaTrack::getAlbum, "Album", 3);
	fields->add<std::string,Variant>(&MediaTrack::getTitle, "Title", 4);
	fields->add<std::string,Variant>(&MediaTrack::getGenre, "Genre", 5);
	return fields;
 }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////

 }; // namespace entertainment
}; // namespace wosh
